﻿<%@ Page Title="SicoNide Blending" Language="C#" MasterPageFile="~/TableMaster.master" AutoEventWireup="true" CodeFile="SicoNideBlending.aspx.cs" Inherits="Pages_SicoNideBlending" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <style>
        @media only screen and (max-width: 760px), (min-device-width: 768px) and (max-device-width: 1024px) {

            .resTbl tr:nth-of-type(odd) {
                background-color: #CDE2FF;
            }

            .resTbl tr:nth-of-type(1) {
                display: none;
            }

            .resTbl td:nth-of-type(1):before {
                content: "Blending Date";
            }

            .resTbl td:nth-of-type(2):before {
                content: "Seed Drum";
            }

            .resTbl td:nth-of-type(3):before {
                content: "Charge Number";
            }

            .resTbl td:nth-of-type(4):before {
                content: "Notes";
            }

            .resTbl td:nth-of-type(5):before {
                content: "Created By";
            }

            .resTbl td:nth-of-type(6):before {
                content: "Created Date";
            }
        }
    </style>


    <script>
        function save() {
            var Blending_Date = $('#MainContent_Add_txtBlending_Date').val();
            var Seed_Drum = $('#MainContent_Add_txtSeed_Drum').val();
            var Charge_Number = $('#MainContent_Add_txtCharge_Number').val();
            var Notes = $('#MainContent_Add_txtNotes').val();
            var Baginput = $('#MainContent_Add_ddlBag_Drum_Input').val();
            var BaginputNum = $('#MainContent_Add_txtBag_Drum_Input_Num').val();
            if (Blending_Date == "") {
                alert('Please enter Blending Date');
                return;
            }
            if (Baginput == "0") {
                alert('Please Select Bag or Drum');
                return;
            }
            if (BaginputNum == "") {
                alert('Please enter Bag or Drum Number');
                return;
            }
            if (Seed_Drum == "") {
                alert('Please enter Seed Drum');
                return;
            }
            if (Charge_Number == "") {
                alert('Please enter Charge Number');
                return;
            }
            if (Notes == "") {
                alert('Please enter Notes');
                return;
            }
            var siconideblending_vessels = 0;

            var sv_inputs = ["MainContent_Add_ddlBag_Drum_Input", "MainContent_Add_txtBag_Drum_Input_Num"];
            var sv_Fields = ["Drum_Bag", "Drum_Bag_Number"];
            var editurl = (window.location.search).split('=');
            var Id = editurl[editurl.length - 1];
            if (Id == "") {
            var json = "[";
            json = "{";
            json += '"Blending_Date"' + ':' + '"' + Blending_Date + '"';
            json += ',"Seed_Drum"' + ':' + '"' + Seed_Drum + '"';
            json += ',"Charge_Number"' + ':' + '"' + Charge_Number + '"';
            json += ',"Notes"' + ':' + '"' + Notes + '"';
            
            json += ',"siconideblending_vessels"' + ':' + getValues('mytable1', sv_Fields, sv_inputs);

            json += "}";
           // json += "]";
           
                saveJSonArrays(json, 'save_sicoNideBlending');
            }
            else {

                var json = "[";
                json = "{";
                json += '"ID"' + ':' + '"' + Id + '"';
                json += ',"Blending_Date"' + ':' + '"' + Blending_Date + '"';
                json += ',"Seed_Drum"' + ':' + '"' + Seed_Drum + '"';
                json += ',"Charge_Number"' + ':' + '"' + Charge_Number + '"';
                json += ',"Notes"' + ':' + '"' + Notes + '"';

                json += ',"siconideblending_vessels"' + ':' + getValues('mytable1', sv_Fields, sv_inputs);

                json += "}";
                //json += "]";

                saveJSonArrays(json, 'update_sicoNideBlending');
                var urlredirect = "http://" + window.location.host + window.location.pathname;
                top.location = urlredirect;

            }
        }
    </script>


</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="Add" runat="Server">


    <asp:Panel ID="pnlAdd" runat="server">

        <table cellpadding="0" cellspacing="0" style="width: 100%;">

            <tr>
                <td style="width: 170px">
                    <asp:Label ID="lblBlending_Date" runat="server" AssociatedControlID="txtBlending_Date" Text="Blending Date:"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtBlending_Date" runat="server" type="date"></asp:TextBox>
                </td>
            </tr>
            <td colspan="2">
                    <button type="button" class="btn btn-default btn-xs" onclick="addRow('mytable1');"><span class="glyphicon glyphicon-plus"></span>Add Bag or Drum</button>
                    <table id="mytable1" cellpadding="0" cellspacing="0">
                        <tr>
                            <td style="width: 170px">
                                <asp:Label ID="lblBag_Drum_Input" runat="server" AssociatedControlID="ddlBag_Drum_Input" Text="Bag or Drum"></asp:Label>
                            </td>
                            <td>
                                <asp:Label ID="lblBag_Drum_Input_Num" runat="server" AssociatedControlID="txtBag_Drum_Input_Num" Text="Bag or Drum #"></asp:Label>
                            </td>
                            <td></td>
                        </tr>
                        <tr>
                            <td style="width: 170px">
                                <asp:DropDownList ID="ddlBag_Drum_Input" runat="server" DataSourceID="Ds_Bag_Drum" DataTextField="VESSEL_TYPE" DataValueField="VESSEL_ID" OnDataBound="ddlBag_Drum_Input_DataBound">
                                </asp:DropDownList>
                                <asp:ObjectDataSource ID="Ds_Bag_Drum" runat="server" SelectMethod="selectAll" TypeName="DAL_tbl_vessel_master"></asp:ObjectDataSource>
                            </td>
                            <td>
                                <asp:TextBox ID="txtBag_Drum_Input_Num" runat="server"></asp:TextBox>
                            </td>
                            <td>
                                <button type="button" class="btn btn-default btn-xs" onclick="removeRow(this);"><span class="glyphicon glyphicon-remove"></span></button>
                            </td>
                        </tr>
                    </table>
                </td>
            <tr>
                <td style="width: 170px">
                    <asp:Label ID="lblSeed_Drum" runat="server" AssociatedControlID="txtSeed_Drum" Text="Seed Drum:"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtSeed_Drum" runat="server" ></asp:TextBox>
                </td>
            </tr>

            <tr>
                <td style="width: 170px">
                    <asp:Label ID="lblCharge_Number" runat="server" AssociatedControlID="txtCharge_Number" Text="Charge Number:"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtCharge_Number" runat="server" Validate="Number"></asp:TextBox>
                </td>
            </tr>

            <tr>
                <td style="width: 170px">
                    <asp:Label ID="lblNotes" runat="server" AssociatedControlID="txtNotes" Text="Notes:"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtNotes" runat="server" TextMode="MultiLine" Height="58px" Width="232px"></asp:TextBox>
                </td>
            </tr>

            


            <tr>
                <td style="width: 170px">&nbsp;</td>
                <td>
                    <input type="button" value="Save" style="width:90px" class="btn btn-success" onclick="save();" />
                    <%--<asp:Button ID="btnSave" runat="server" CssClass="btn btn-success" OnClick="btnSave_Click" Text="Save" Width="90px" />--%>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <asp:Button ID="btnCancel" runat="server" CssClass="btn btn-danger" OnClick="btnCancel_Click" Text="Cancel" Width="90px" />

                </td>
            </tr>

        </table>

    </asp:Panel>

</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="Grid" runat="Server">

    <asp:Panel ID="pnlList" runat="server">
        <asp:GridView ID="gridClients" runat="server" AutoGenerateColumns="False" CssClass="resTbl" DataSourceID="DS_tbl_siconideblending">
            <Columns>
                <asp:BoundField DataField="Blending_Date" HeaderText="Blending Date" SortExpression="Blending_Date" DataFormatString="{0:yyMMdd}"/>
                <asp:BoundField DataField="Seed_Drum" HeaderText="Seed Drum" SortExpression="Seed_Drum" />
                <asp:BoundField DataField="Charge_Number" HeaderText="Charge Number" SortExpression="Charge_Number" />
                <asp:BoundField DataField="Notes" HeaderText="Notes" SortExpression="Notes" />
                <asp:BoundField DataField="CREATED_BY" HeaderText="Created By" SortExpression="CREATED_BY" />
                <asp:BoundField DataField="CREATED_DATE" HeaderText="Created Date" SortExpression="CREATED_DATE" DataFormatString="{0:yyMMdd}"/>

                <asp:TemplateField HeaderText="Edit">
                    <ItemTemplate>
                        <asp:LinkButton ID="linkEdit" runat="server" Text="Edit" CommandArgument='<%# Eval("ID") %>' OnClick="linkEdit_Click"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Delete">
                    <ItemTemplate>
                        <asp:LinkButton ID="linkDelete" CommandName="delete" runat="server" Text="Delete" OnClientClick="javascript:return confirm('Are you sure you want to delete this record?');" CommandArgument='<%# Eval("ID") %>' OnClick="linkDelete_Click"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <asp:ObjectDataSource ID="DS_tbl_siconideblending" runat="server" SelectMethod="selectAllForGrid" DeleteMethod="delete" InsertMethod="insert" UpdateMethod="update" TypeName="DAL_tbl_siconideblending">
            <DeleteParameters>
                <asp:Parameter Name="ID" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="Blending_Date" Type="DateTime" />
                <asp:Parameter Name="Seed_Drum" Type="String" />
                <asp:Parameter Name="Charge_Number" Type="Decimal" />
                <asp:Parameter Name="Notes" Type="String" />
                <asp:Parameter Name="CREATED_BY" Type="String" />
                <asp:Parameter Name="CREATED_DATE" Type="DateTime" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="Blending_Date" Type="DateTime" />
                <asp:Parameter Name="Seed_Drum" Type="String" />
                <asp:Parameter Name="Charge_Number" Type="Decimal" />
                <asp:Parameter Name="Notes" Type="String" />
                <asp:Parameter Name="UPDATED_BY" Type="String" />
                <asp:Parameter Name="UPDATED_DATE" Type="DateTime" />
            </UpdateParameters>
        </asp:ObjectDataSource>
    </asp:Panel>
</asp:Content>

